package org.fastiot.data.sampling

import grails.testing.gorm.DomainUnitTest
import spock.lang.Specification

class LatestSpec extends Specification implements DomainUnitTest<Latest> {

    def setup() {
    }

    def cleanup() {
    }

    void "Test a valid properties"() {
        given:
        def instance = new Latest(
                packetCode: packetCode, hexPacketCode: hexPacketCode, dateAcquired: dateAcquired,
                terminalCode: terminalCode, metadata: metadata, contents: contents
        )

        when:
        instance.save(flush: true)

        then:
        !instance.hasErrors()

        where:
        packetCode << [2304, null, 0x0900]
        hexPacketCode << [null, "0900", null]
        terminalCode << ["LN1234567890123456", "LN1234567890123456", "LN1234567890123456"]
        dateAcquired << [new Date(), new Date(), new Date()]
        metadata << [[Oid: "LN1234567890123456", Pid: 0x0900], [DateSent: "2018-02-14 12:13:14", "RemoteAddress": "10.11.12.13:23462"], [SN: 1234, DateReceived: "2018-02-14 12:13:14"]]
        contents << [[SOC: 80, MPH: 37.5], [LAT: 39.5427, LON: 116.2317], [TEMP: 80.3, VIB: 10.5]]
    }
}
